package com.example.administrator.myapplication.Util;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.administrator.myapplication.Bean.User;
import com.google.gson.Gson;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by Administrator on 2019/10/10 0010.
 */

public class SharedPreferencesUtil {
    public static void  saveUser(Context context,User user){
        SharedPreferences.Editor editor = context.getSharedPreferences("currUser", MODE_PRIVATE).edit();
        editor.putString("userJson", new Gson().toJson(user));
        editor.apply();
    }
    public static User getUser(Context context){
        return new Gson().fromJson(context.getSharedPreferences("currUser",MODE_PRIVATE).getString("userJson",null),User.class);
    }
}
